package cn.tworice.admin.service;

import cn.tworice.admin.dao.AdminDistDao;
import cn.tworice.common.entity.code.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminDistService implements InductsListenerService<AdminDist>, CrudService<AdminDist> {
    @Autowired
    private AdminDistDao dao;

    public List<AdminDist> getList(Integer page, Integer pageSize, AdminDist entity) {
        return dao.queryList(page * pageSize, pageSize, entity);
    }

    public int getTotal(AdminDist entity) {
        return dao.queryTotal(entity);
    }

    public int set(AdminDist entity) {
        if (entity.getId() == null) {
            entity.setDate(System.currentTimeMillis());
            return dao.insert(entity);
        } else {
            return dao.update(entity);
        }
    }

    public int del(Integer[] ids) {
        return dao.del(ids);
    }

    @Override
    public int save(List<AdminDist> list) {
        list.forEach(item -> {
            item.setDate(System.currentTimeMillis());
        });
        return dao.insertList(list);
    }

    public AdminDist getInfo(Integer id) {
        return dao.queryInfo(id);
    }
}